package com.example.aidl;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.widget.Button;

import com.googlecode.androidannotations.annotations.Click;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.ViewById;

@EActivity(R.layout.second_activity)
public class SecondActivity extends Activity {
	PeopleAIDL peopleAIDL;
	@ViewById
	Button button1,button2;
	
	private ServiceConnection conn = new ServiceConnection(){
		public void onServiceConnected(ComponentName className, IBinder service) {
			peopleAIDL=PeopleAIDL.Stub.asInterface(service);
		}

		public void onServiceDisconnected(ComponentName className) {
		}
	};
	
	@Click
	void button1()
	{
		bindService(new Intent(this, AIDLService_.class), conn, Context.BIND_AUTO_CREATE);
	}
	@Click
	void button2()
	{
		try {
			peopleAIDL.say();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
